﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LiteQueryWPF
{
    /// <summary>
    /// ImportGuide.xaml 的交互逻辑
    /// </summary>
    public partial class ImportGuide : MahApps.Metro.Controls.MetroWindow
    {
        List<Controls.FileRowPanel> _rows;
        public List<Controls.FileRowPanel> Rows
        {
            get { return _rows; }
        }

        public ImportGuide()
        {
            InitializeComponent();
            _rows = new List<Controls.FileRowPanel>();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dlg = Common.WinForm.OpenFileDialog(mul: true);
            if (dlg.Item1 == true)
            {
                var files = dlg.Item2.FileNames;
                foreach (var item in files)
                {
                    var file = new System.IO.FileInfo(item);
                    txtPath.Text = file.DirectoryName;
                    var row = new Controls.FileRowPanel(file);
                    row.OnRemoved += (ss, ee) =>
                    {
                        if (_rows.Contains(row))
                            _rows.Remove(row);
                    };
                    _rows.Add(row);
                    spContent.Children.Add(row);
                }
            }
        }

        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }
    }
}
